package com.heima.article.listen;

import com.alibaba.fastjson.JSON;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ArticleService;
import com.heima.common.constants.WemediaConstants;
import com.heima.model.wemedia.dtos.WmUpdateCommentDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class ArticleCommentListen {
    @Autowired
    private ApArticleConfigService apArticleConfigService;

    /**
     * 打开或关闭关闭评论
     * @param message
     */
    @KafkaListener(topics = WemediaConstants.COMMENT_TOPIC)
    public void ArticleCommentList(String message){
        if (StringUtils.isNotBlank(message)) {
            WmUpdateCommentDto dto = JSON.parseObject(message, WmUpdateCommentDto.class);
            //修改文章状态
            apArticleConfigService.updateCommentStatus(dto);
        }
    }
}
